package swing.chapter03;

import swing.util.SwingConsle;

import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;

/**
 * Tab页
 */
public class TabbedPane1 extends JFrame {
    private String [] language = {"Java", "C++", "Python", "R", "Go", "Javascript", "Html", "Jsp", "PHP"};
    private JTabbedPane tabs = new JTabbedPane();
    private JTextField txt = new JTextField(20);

    public TabbedPane1(){
        for(int i=0;i<language.length;i++){
            tabs.addTab(language[i], new JButton("Tabbed pane " + i));
        }

        tabs.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                txt.setText("Tab selected :" + tabs.getSelectedIndex());
            }
        });

        add(BorderLayout.SOUTH, txt);
        add(tabs);
    }

    public static void main(String[] args) {
        SwingConsle.run(new TabbedPane1(), 800, 600);
    }
}
